<?php
defined('BY_JYA') or exit('Access Denied');
/*
	pc端页面组件安装升级接口
*/
if($do=='check'){
	$ids=trim($_RQ['ids']);
	if(!$ids){
		eci('页面参数错误！','error');
	}
	$ids=explode(';',$ids);
	$pc_blocks=pdo_getall('core_pc_blocks',array('id'=>$ids),array('id','release'),'id');
	eci($pc_blocks);
}
if($do=='getbuyed'){
	$installed=trim($_RQ['installed']);
	if($installed){
		$installed=explode(';',$installed);
	}
	$trades=pdo_getall('core_trade',array('uniacid'=>$_SESSION['uniacid'],'type'=>6),array('pid'),'pid');
	if(!$trades){
		eci(array());
	}
	$trades=array_keys($trades);
	if($installed){
		$trades=array_diff($trades,$installed);
	}
	if(!$trades){
		eci(array());
	}
	$blocks=pdo_getall('core_pc_blocks',array('status'=>1,'show'=>1,'id'=>$trades),array('id','title','release','image'));
	eci($blocks);
}
if($do=='install'){
	$id=intval($_RQ['id']);
	if(!$id){
		eci('请先选择要安装的组件！','error');
	}
	check_buy($id,6);
	check_install($id,6);
	$block=pdo_get('core_pc_blocks',array('id'=>$id),array('type','showhtml','edithtml','title','name','default','release','image'));
	if(!$block){
		eci('要安装的组件不存在！','error');
	}
	if(!$block['showhtml'] || !$block['edithtml']){
		eci('该组件存在问题，重要参数未设置，请联系云平台客服！','error');
	}
	$block['image']=$block['image']?tomedia($block['image']):'';
	$block['showhtml']=cfc('files')->source_read($block['showhtml']);
	$block['edithtml']=cfc('files')->source_read($block['edithtml']);
	/*$local_id=pdo_getcolumn('app_install_id',array('uniacid'=>$_SESSION['uniacid'],'type'=>6),'auto');
	if(!$local_id){
		$local_id=0;
	}
	$local_id++;
	pdo_update('app_install_id',array('auto'=>$local_id),array('uniacid'=>$_SESSION['uniacid'],'type'=>6));
	$app_install=array('uniacid'=>$_SESSION['uniacid'],'type'=>6,'pid'=>$id,'local_id'=>$local_id);
	pdo_insert('app_install',$app_install);
	$block['id']=$local_id;*/
	eci($block);
}
if($do=='update'){
	$id=intval($_RQ['id']);
	if(!$id){
		eci('请先选择要更新的组件！','error');
	}
	$block=pdo_get('core_pc_blocks',array('id'=>$id),array('type','showhtml','edithtml','title','name','default','release','id','image'));
	if(!$block){
		eci('要更新的组件不存在！','error');
	}
	if(!check_buy($block['id'],6)){
		eci('您尚未购买组件！','error');
	}
	$block['image']=$block['image']?tomedia($block['image']):'';
	$block['showhtml']=cfc('files')->source_read($block['showhtml']);
	$block['edithtml']=cfc('files')->source_read($block['edithtml']);
	unset($block['id']);
	eci($block);
}

eci('无效操作符！','error');